<?php
/**
 * ShopEx licence
 *
 * @copyright  Copyright (c) 2005-2010 ShopEx Technologies Inc. (http://www.shopex.cn)
 * @license  http://ecos.shopex.cn/ ShopEx License
 */ 


class b2c_mdl_member_fans extends dbeav_model{
	/**
	 * 构造方法
	 * @param object model相应app的对象
	 * @return null
	 */
    public function __construct($app){
        parent::__construct($app);
    }
//  获取当前用户的所有粉丝信息
    public function get_fans_list($member_id,$limit=-1,$offset=0){
        $sql = "select m.member_id,m.name,m.avatar,f.created from ".kernel::database()->prefix."b2c_members as m
                left join (select fans_id,created from ".kernel::database()->prefix."b2c_member_fans where member_id = {$member_id}) as f
                on m.member_id = f.fans_id order by f.created desc";
        $list = kernel::database()->selectLimit($sql,$limit,$offset);
        foreach($list as $key=>$info){
            if(app::get("b2c")->model('members')->is_exists_memberid($info['member_id'])){
                $list[$key]['avatar'] = base_storager::image_path($info['avatar'],'s');
            }else{
                unset($list[$key]);
            }
        }
        return $list;
    }
//    public function getList($cols = '*', $filter = array(), $offset = 0, $limit = -1, $orderType = null) {
//        $fans = parent::getList($cols, $filter, $offset, $limit, $orderType);
//        foreach($fans as $k=>$val){
//            if(!app::get("b2c")->model('members')->is_exists_memberid($val['member_id']) || !app::get("b2c")->model('members')->is_exists_memberid($val['fans_id'])){
//                unset($fans[$k]);
//            }
//        }
//        return $fans;
//    }
}
